import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import CLIPSJNI.Environment;


/* Implement FindFact which returns just a FactAddressValue or null */
/* TBD Add size method to PrimitiveValue */

class PersonalidadPanel extends JPanel {

    /**
     * 
     */
    private static final long serialVersionUID = -4063363776674394295L;

    JLabel dLabel;

    JComboBox estudiosoField;
    JComboBox responsableLabel;

    JComboBox atentoLabel;

    JComboBox aplicadoLabel;

    JComboBox inteligenteLabel;

    JComboBox creativoLabel;

    JComboBox logicoLabel;
    JComboBox emocionalLabel;

    JComboBox consideradoLabel;

    JComboBox solidarioLabel;
    JButton nextButton;
    JButton prevButton;
    JPanel choicesPanel;
    ButtonGroup choicesButtons;
    
	
	PrintWriter writer;

    Environment clips;

    public PersonalidadPanel()  {

        /* ================================ */
        /* Create a new JFrame container. */
        /* ================================ */

        final JFrame jfrm = new JFrame("TestVocacionalDemo");

        /* ============================= */
        /* Specify FlowLayout manager. */
        /* ============================= */

        jfrm.getContentPane().setLayout(new GridLayout(1, 1));

        /* ================================= */
        /* Give the frame an initial size. */
        /* ================================= */

        jfrm.setSize(750, 500);
        jfrm.setLocation(200, 100);

        /* ============================================================= */
        /* Terminate the program when the user closes the application. */
        /* ============================================================= */

        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        /* =========================== */
        /* Create the display panel. */
        /* =========================== */

        JPanel displayPanel = new JPanel();
        JLabel displayLabel = new JLabel();
        displayPanel.add(displayLabel);

        /* =========================== */
        /* Create the choices panel. */
        /* =========================== */
		
        choicesPanel = new JPanel();
        choicesPanel.setBorder(BorderFactory.createTitledBorder("Personalidad del alumno"));
       
        choicesPanel.setSize(400, 400);
        choicesPanel.setLayout(new BoxLayout(choicesPanel, BoxLayout.Y_AXIS));
        

        dLabel = new JLabel("Estudioso");
        choicesPanel.add(dLabel);
        estudiosoField = new JComboBox();
        estudiosoField.addItem("alto");
        estudiosoField.addItem("medio");
        estudiosoField.addItem("bajo");
        choicesPanel.add(estudiosoField);

        dLabel = new JLabel("Responsable");
        choicesPanel.add(dLabel);
        responsableLabel = new JComboBox();
        responsableLabel.addItem("alto");
        responsableLabel.addItem("medio");
        responsableLabel.addItem("bajo");
        choicesPanel.add(responsableLabel);

        dLabel = new JLabel("Atento");
        choicesPanel.add(dLabel);
        atentoLabel = new JComboBox();
        atentoLabel.addItem("alto");
        atentoLabel.addItem("medio");
        atentoLabel.addItem("bajo");
        choicesPanel.add(atentoLabel);

        dLabel = new JLabel("Aplicado");
        choicesPanel.add(dLabel);
        aplicadoLabel = new JComboBox();
        aplicadoLabel.addItem("alto");
        aplicadoLabel.addItem("medio");
        aplicadoLabel.addItem("bajo");
        choicesPanel.add(aplicadoLabel);

        dLabel = new JLabel("Inteligente");
        choicesPanel.add(dLabel);
        inteligenteLabel = new JComboBox();
        inteligenteLabel.addItem("alto");
        inteligenteLabel.addItem("medio");
        inteligenteLabel.addItem("bajo");
        choicesPanel.add(inteligenteLabel);

        dLabel = new JLabel("Creativo");
        choicesPanel.add(dLabel);
        creativoLabel = new JComboBox();
        creativoLabel.addItem("alto");
        creativoLabel.addItem("medio");
        creativoLabel.addItem("bajo");
        choicesPanel.add(creativoLabel);

        dLabel = new JLabel("Logico");
        choicesPanel.add(dLabel);
        logicoLabel = new JComboBox();
        logicoLabel.addItem("alto");
        logicoLabel.addItem("medio");
        logicoLabel.addItem("bajo");
        choicesPanel.add(logicoLabel);

        dLabel = new JLabel("Emocional");
        choicesPanel.add(dLabel);
        emocionalLabel = new JComboBox();
        emocionalLabel.addItem("alto");
        emocionalLabel.addItem("medio");
        emocionalLabel.addItem("bajo");
        choicesPanel.add(emocionalLabel);

        dLabel = new JLabel("Considerado");
        choicesPanel.add(dLabel);
        consideradoLabel = new JComboBox();
        consideradoLabel.addItem("alto");
        consideradoLabel.addItem("medio");
        consideradoLabel.addItem("bajo");
        choicesPanel.add(consideradoLabel);

        dLabel = new JLabel("Solidario");
        choicesPanel.add(dLabel);
        solidarioLabel = new JComboBox();
        solidarioLabel.addItem("alto");
        solidarioLabel.addItem("medio");
        solidarioLabel.addItem("bajo");
        choicesPanel.add(solidarioLabel);

        /* =========================== */
        /* Create the buttons panel. */
        /* =========================== */

        
        try {
            writer = new PrintWriter("factsPersonalidad.clp", "UTF-8");

        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        JPanel buttonPanel = new JPanel();



        nextButton = new JButton("Next");
        nextButton.setActionCommand("Next");
        choicesPanel.add(nextButton);
        nextButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                HistorialAcademico historialPanel = new HistorialAcademico();
				
				
				writer.println("(deffacts caso_1 " );
				writer.println("	(personalidad_alumno " );
				writer.println("		(estudioso "+estudiosoField.getSelectedItem().toString()+")");
				writer.println("		(responsable "+responsableLabel.getSelectedItem().toString()+")");
				writer.println("		(atento "+atentoLabel.getSelectedItem().toString()+")" );
				writer.println("		(aplicado "+aplicadoLabel.getSelectedItem().toString()+")");
				writer.println("		(inteligente "+inteligenteLabel.getSelectedItem().toString()+")");
				writer.println("		(creativo "+creativoLabel.getSelectedItem().toString()+")");
				writer.println("		(logico "+logicoLabel.getSelectedItem().toString()+")");
				writer.println("		(emocional "+emocionalLabel.getSelectedItem().toString()+")");
				writer.println("		(considerado "+consideradoLabel.getSelectedItem().toString()+")" );
				writer.println("		(solidario "+solidarioLabel.getSelectedItem().toString()+")))");
				writer.close();
				
				
                historialPanel.setVisible(true);
                jfrm.setVisible(false);

				

            }
        });

        /* ===================================== */
        /* Add the panels to the content pane. */
        /* ===================================== */

        jfrm.getContentPane().add(displayPanel);
        jfrm.getContentPane().add(choicesPanel);
        jfrm.getContentPane().add(buttonPanel);

        /* ==================== */
        /* Display the frame. */
        /* ==================== */

        jfrm.setVisible(true);
        displayLabel.setText("Run clips file");
        /* ================================== */
        /* Get the current state of the UI. */
        /* ================================== */

    }


}
